from flask_login import login_required
from app.model.order import orderhtml, salehtml, typepolarhtml, storehtml, storemonitor
from flask import send_file
from app.model.dataget import getrawdata
from . import web

@web.route('/')
@login_required
def app_0():
    return "<style>.content{height:800px;} a{ color:#333333;text-decoration: none;} a:visited {" \
           "color:#333333} </style>" \
           "<br><br><br><br><br><h1 align='center'>YumChina 订单数据</h1> <br><br><br>" \
           "<p style='text-align:center'><a href='/six'> <font size=5>获取数据</a> <br>" \
           "<a href='/one' target='_blank'> 当日订单总量及金额</a> <br>" \
           "<a href='/two' target='_blank'>当日订单类别分布</a> <br> " \
           "<a href='/three' target='_blank'>各IT部门订单类别</a> <br> " \
           "<a href='/four' target='_blank'>订单量排行前后二十门店</a> <br> " \
           "<a href='/five' target='_blank'>所有门店数据库心跳间隔监控</a></p> <br> "


@web.route('/six')
@login_required
def app_6():
    global data2, searchtime
    data2, searchtime = getrawdata ()
    return app_0 ()


@web.route('/one')
@login_required
def app_1():
    try:
        salehtml (data2, searchtime)
        return send_file ("sale.html")
    except NameError:
        return "请先获取数据"


@web.route('/two')
@login_required
def app_2():
    try:
        orderhtml (data2, )
        return send_file ("order.html")
    except NameError:
        return "请先获取数据"


@web.route('/three')
@login_required
def app_3():
    try:
        typepolarhtml (data2)
        return send_file ("typepolar.html")
    except NameError:
        return "请先获取数据"


@web.route('/four')
@login_required
def app_4():
    try:
        storehtml (data2, searchtime)
        return send_file ("topsale.html")
    except NameError:
        return "请先获取数据"


@web.route('/five')
@login_required
def app_5():
    try:
        storemonitor (data2, searchtime)
        return send_file ("storemonitor.html")
    except NameError:
        return "请先获取数据"

